#include<stdio.h>
#include<iostream>
using namespace std;
typedef struct TNode
{
    char Data;
    struct TNode * lchild;
    struct TNode * rchild;
}*PTree,Tree;
void PreorderTraverse(PTree T);
void CreateTree(PTree *T,char l,char r);
void FindTree(PTree *T,char ele,char l,char r);
int main()
{
    //freopen("in.txt","r",stdin);
    PTree T = (PTree)malloc(sizeof(Tree));
    char s[4];
    int n;
    cin>>n;
    cin >> s;
    T->Data = s[0];
    if(n > 0)
    {
        if(s[1] != '*')
        {
            PTree p = (PTree)malloc(sizeof(Tree));
            p->Data = s[1];
            p->lchild = NULL;
            p->rchild = NULL;
            T->lchild = p;
        }
        if(s[2] != '*')
        {
            PTree p = (PTree)malloc(sizeof(Tree));
            p->Data = s[2];
            p->lchild = NULL;
            p->rchild = NULL;
            T->rchild = p;
        }
    }
    //printf("%c%c%c",T->Data,T->lchild->Data,T->rchild->Data);
    for(int i = 0; i < n - 1; i++)
    {
        cin>>s;
        FindTree(&T,s[0],s[1],s[2]);
    }
    PreorderTraverse(T);
}

void CreateTree(PTree *T,char l,char r)
{
    //printf("%c%c%c\n",(*T)->Data,l,r);
    //printf("%c",(*T)->Data);
    if(l != '*')
    {
        PTree p = (PTree)malloc(sizeof(Tree));
        p->Data = l;
        p->lchild = NULL;
        p->rchild = NULL;
        (*T)->lchild = p;
    }
    if(r != '*')
    {
        PTree p = (PTree)malloc(sizeof(Tree));
        p->Data = r;
        p->lchild = NULL;
        p->rchild = NULL;
        (*T)->rchild = p;
    }
}

void FindTree(PTree *T,char ele,char l,char r)
{
    if((*T)!=NULL)
    {
        if((*T)->Data == ele) 
        {
            CreateTree(T,l,r);
            //printf("a==%c%c%c\n",ele,l,r);
        }
        else
        {
            //printf("%c%c%c%c\n",(*T)->Data,ele,l,r);
            if((*T)->lchild) FindTree(&((*T)->lchild),ele,l,r);
            if((*T)->rchild) FindTree(&((*T)->rchild),ele,l,r);
        }
    }
}

void PreorderTraverse(PTree T)
{
    if(T!=NULL)
    {
        printf("%c",T->Data);
        PreorderTraverse(T->lchild);
        PreorderTraverse(T->rchild);
    }
}

